<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>恒铸智能柜管理平台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/layui/css/layui.css" media="all"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/layui/layui.js"></script>
</head>
<style>
    .laytable-cell-1-url {
        width: 340px !important;
    }
</style>
<body class="childrenBody">
<blockquote class="layui-elem-quote admin_search">
    <div>
        <a class="layui-btn addbtn" id="addbtn">新增</a>

    </div>
</blockquote>
<table id="FAQ" lay-filter="FAQ"></table>

<!--操作-->
<script type="text/html" id="publish">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
</script>
<script>
    layui.use(['form', 'layer', 'laydate', 'table', 'laytpl'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        $("#addbtn").on("click",function(){
            layui.layer.open({
                title: "添加",
                type: 2,
                area: ['380px', '280px'],
                content: '/applet/add',
            })
        })

        var tableIns = table.render({
            elem: '#FAQ',
            url: '/applet/list',
            cellMinWidth: 95,
            page: true,
            where:{sgin:1},
            height: "full-205",
            limit: 10,
            limits: [10, 15, 20, 25],
            id: "FAQ",
            cols: [[
                {field: 'title', title: '标题',edit: 'text', align: 'center'},
                {field: 'content', title: '内容',edit: 'text', align: 'center'},
                {field: 'time', title: '最后修改时间',edit: 'text', align: 'center'},
                {title: '操作', width: 90, templet: '#publish', fixed: "right", align: "center"}
            ]]
        });


        layui.use('table', function () {
            var table = layui.table;

            //监听单元格编辑
            table.on('edit(FAQ)', function (obj) {
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段

                // console.log(data.id+"===="+field+"---"+value)

                var param;

                if(field == "title"){
                    param={"id":data.id,"title":value,"sign":1}
                }else if(field == "content"){
                    param={"id":data.id,"content":value,"sign":1}
                }
                $.post("/applet/edit", param, function (res) {
                    if (res.success) {
                        layer.msg(res.message)
                        tableIns.reload();
                    } else {
                        layer.msg(res.message)
                    }
                })
            });
        });

        //列表操作
        table.on('tool(FAQ)', function (obj) {
            var layEvent = obj.event,
                data = obj.data;


            if (layEvent === 'del') {

                layer.confirm('确定删除此账户？', {icon: 3, title: '提示信息'}, function (index) {
                    // console.log(index)
                    if (index) {
                        $.get("/applet/edit", {id:data.id,sign:4}, function (res) {
                            if (res.success) {
                                layer.msg("删除成功");
                                tableIns.reload();
                            } else {
                                layer.open({
                                    title: '温馨提示'
                                    , content: res.message
                                });
                                tableIns.reload();
                            }
                            ;
                        });
                    } else {
                        tableIns.reload();
                    };
                });

            }
        });

    })
</script>
</body>
</html>